import ujson
from fastapi import Path, Request
from fastapi.encoders import jsonable_encoder
from pydantic import BaseModel, Field

from common.utils.depends.common import get_mgw
from common.g.g import G_REDIS
from enums.spu_enum import SPUTypeEnum, SPUPriceTypeEnum


class SearchSPUListModel(BaseModel):
    name: str = Field(None, description="spu名字", max_length=64)
    spu_type: SPUTypeEnum = Field(None, description="spu 类型")
    code: str = Field(None, description="spu code", max_length=32)
    onsale: bool = Field(None, description="是否在售")
    price_type: SPUPriceTypeEnum = Field(None, description="商品定价类型")


async def get_mall_info(request: Request, code: str = Path(..., max_length=16)):
    from service.mall_service import MallService
    mgw = get_mgw(request)
    ms = MallService(mgw, G_REDIS)
    _, data = await ms.get_mall_info_by_code(code)
    return data

